Use case: USART RX in DMA mode ¶
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
#define DATA_TO_RECEIVE_SIZE 255
uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];
USART_HandleTypeDef husart;
/* Ensure that all required peripherals
(USART, GPIO, DMA, NVIC,etc.) are configured properly
/*
...
*/
/* USART register Receive complete user callback */
HAL_USART_RegisterCallback(&husart, HAL_USART_RX_CB_ID,
USART_RxCpltCallback);
/* Start a USART Process in DMA mode */
HAL_USART_Receive_DMA(&husart, aRxBuffer,
DATA_TO_RECEIVE_SIZE)
|
#define DATA_TO_RECEIVE_SIZE 255
uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];
hal_usart_handle_t husart;
/* Ensure that all required peripherals
(USART, GPIO, DMA, NVIC,etc.) are configured properly
/*
...
*/
/* USART register Receive complete user callback */
HAL_USART_RegisterRxCpltCallback(&husart, USART_RxCpltCallback);
/* Start a USART Process in DMA mode */
HAL_USART_Receive_DMA(&husart, aRxBuffer,
DATA_TO_RECEIVE_SIZE)
|
Key changes ¶
HAL2 DMA start uses
HAL_DMA_StartPeriphXfer_IT_Opt()(optional interrupt generation) instead ofHAL_DMA_Start_IT().HAL2 provides a dedicated registration API for RX completion callbacks:
HAL_USART_RegisterRxCpltCallback().

